from rest_framework.decorators import renderer_classes, api_view 
from rest_framework_swagger.renderers import OpenAPIRenderer, SwaggerUIRenderer 
import coreapi 
from rest_framework import response 
# noinspection PyArgumentList 
@api_view() 
@renderer_classes([SwaggerUIRenderer, OpenAPIRenderer]) 
def schema_view(request): 
  print("---inside schema view-----") 
  # noinspection PyArgumentList 
  schema = coreapi.Document(
  title='Cunpon API', 
  url='127.0.0.1',
  description='优惠劵API',
  content={ 
    '商品信息': {
      'goods_lists': coreapi.Link(
        url='/coupon/goods_list/', 
        action='post', 
        fields=[ 
        coreapi.Field(
          name='page', 
          required=True, 
          location='query', 
          description='page' 
        ), 
        coreapi.Field(
          name='page_size', 
          required=True, 
          location='query', 
          description='page size' 
        ),
        coreapi.Field(
          name='keywords',
          required=False,
          location='query',
          description='keywords'
        ) 
        ], 
        description='获取商品列表' 
      ),
      'coupon_detail': coreapi.Link(
        url='/coupon/coupon_detail',
        action='post',
        fields=[
          coreapi.Field(
            name='ulandUrl',
            required=True,
            location='query',
            description='ulandUrl'
          )
        ],
        description='获取商品优惠劵详情'
      ),
      'goods_detail': coreapi.Link(
        url='/coupon/goods_detail',
        action='post',
        fields=[
          coreapi.Field(
            name='goods_id',
            required=True,
            location='query',
            description='goods_id'
          ),
          # coreapi.Field(
          #   name='ulandUrl',
          #   required=True,
          #   location='query',
          #   description='ulandUrl'
          # )
        ],
        description='获取商品详情'
      ),
      'get_tao_pwd': coreapi.Link(
        url='/coupon/get_tao_pwd',
        action='post',
        fields=[
          coreapi.Field(
            name='uland',
            required=True,
            location='query',
            description='uland'
          )
        ],
        description='生成淘口令'
      )
    },
    '轮播图': {
      'get_home_carousel': coreapi.Link(
        url='/coupon/get_home_carousel/',
        action='get',
        description='获取轮播图'
      )
    },
    '分类相关': {
      'get_primary_classify': coreapi.Link(
        url='/coupon/get_primary_classify/',
        action='get',
        description='获取一级分类'
      ),
      'get_second_classify': coreapi.Link(
        url='/coupon/get_second_classify/',
        action='post',
        fields=[
          coreapi.Field(
            name='upper_level_id',
            required=True,
            location='query',
            description='所属上级'
          )
        ],
        description='获取二级分类'
      )
    },
    '搜索相关': {
      'get_search_auto_result': coreapi.Link(
        url='/coupon/get_search_auto_result/',
        action='get',
        fields=[
          coreapi.Field(
            name='search_query',
            required=True,
            location='query',
            description='搜索内容'
          )
        ]
      ),
      'hot_search_keyword': coreapi.Link(
        url='/coupon/hot_search_keyword/',
        action='post',
        description='热门搜索'
      )
    }
  }) 
  # schema = generator.get_schema(request) 
  print(schema)
  return response.Response(schema)